#!/bin/sh -xe

# remove cruft
rm -f .clang-format .DEPS.git .gn LICENSE.chromium_os OWNERS

# remove more cruft 
find . -name PRESUB\* -execdir rm -f {} \;
find . -name upload.py -execdir rm -f {} \;
find . -name WATCHLISTS -execdir rm -f {} \;
find . -name .gitignore -execdir rm -f {} \;
find . -name .gitmodules -execdir rm -f {} \;
find . -name .gitattributes -execdir rm -f {} \;
find . -name config.sub -execdir rm -f {} \;
find . -name config.guess -execdir rm -f {} \;
find . -name codereview.settings -execdir rm -f {} \;

# remove unused webkit stuff
rm -rf webkit/data
rm -rf webkit/tools
rm -rf third_party/WebKit/Tools
rm -rf third_party/WebKit/ManualTests
rm -rf third_party/WebKit/LayoutTests
rm -rf third_party/WebKit/PerformanceTests

# remove unused media stuff
rm -rf media/tests
rm -rf media/tools

# remove android directories
find . -name android | xargs rm -rf
rm -rf android_webview
rm -rf third_party/android_opengl
rm -rf third_party/android_platform
rm -rf third_party/android_testrunner
rm -f build/protoc_java.gypi \
    build/uiautomator_test.gypi \
    components/web_contents_delegate_android.gypi \

# remove chromeos directories
rm -rf chromeos
rm -rf rlz/chromeos
rm -rf chrome/browser/chromeos

# remove windows directories
rm -rf win8
rm -rf rlz/win
rm -rf sdch/win
rm -rf base/win
rm -rf tools/win
rm -rf ui/gfx/win
rm -rf ui/base/win
rm -rf media/audio/win
rm -rf build/toolchain/win
rm -rf chrome/tools/build/win
rm -rf third_party/win_toolchain

# remove mac directories
find . -name mac | xargs rm -rf
rm -rf third_party/apple*
rm -rf third_party/sudden_motion_sensor
rm -rf third_party/google_toolbox_for_mac

# remove ios directories
rm -rf ios
rm -rf rlz/ios
rm -rf sdch/ios
rm -rf base/ios
rm -rf build/ios
rm -rf media/audio/ios
rm -rf build/config/ios
rm -rf build/toolchain/ios

# these would be useful to remove, but the linux build includes stuff here when it probably shouldn't
# rm -rf sandbox/win
# rm -rf build/win
# rm -rf third_party/JSON

# remove wtl (only used in windows build, also incompatible MS-PL license)
rm -rf third_party/wtl

# automatic updater isn't used
rm -rf google_update

# unused third party stuff
rm -rf third_party/d3
rm -rf third_party/cld
rm -rf third_party/gtk+
rm -rf third_party/flac
rm -rf third_party/mozc
rm -rf third_party/gpsd
rm -rf third_party/swig
rm -rf third_party/mtpd
rm -rf third_party/lcov*
rm -rf third_party/libva
rm -rf third_party/jinja2
rm -rf third_party/talloc
rm -rf third_party/ashmem
rm -rf third_party/scons*
rm -rf third_party/bsdiff
rm -rf third_party/bspatch
rm -rf third_party/tlslite
rm -rf third_party/jsr-305
rm -rf third_party/openmax*
rm -rf third_party/eyesfree
rm -rf third_party/binutils
rm -rf third_party/bintrees
rm -rf third_party/mongoose
rm -rf third_party/tcmalloc
rm -rf third_party/jemalloc
rm -rf third_party/chromite
rm -rf third_party/chromevox
rm -rf third_party/pyftpdlib
rm -rf third_party/pyelftools
rm -rf third_party/webtreemap
rm -rf third_party/simplejson
rm -rf third_party/devscripts
rm -rf third_party/markupsafe
rm -rf third_party/active_doc
rm -rf third_party/icon_match
rm -rf third_party/fuzzymatch
rm -rf third_party/v4l2capture
rm -rf third_party/bidichecker
rm -rf third_party/clang_format
rm -rf third_party/libjpeg_turbo
rm -rf third_party/python_gflags
rm -rf third_party/closure_linter
rm -rf third_party/speech-dispatcher
rm -rf third_party/cros_dbus_cplusplus
rm -rf third_party/accessibility-audit
rm -rf third_party/launchpad_translations
rm -rf third_party/instrumented_libraries
rm -rf third_party/google_appengine_cloudstorage
rm -rf third_party/README.chromium.template

# remove trace-viewer cruft
rm -rf third_party/trace-viewer/examples
rm -rf third_party/trace-viewer/test_data
rm -rf third_party/trace-viewer/third_party/gl-matrix
rm -rf third_party/trace-viewer/third_party/polymer
rm -rf third_party/trace-viewer/third_party/Promises
rm -rf third_party/trace-viewer/third_party/pywebsocket
rm -rf third_party/trace-viewer/third_party/tvcm/third_party/polymer
rm -rf third_party/trace-viewer/third_party/tvcm/third_party/closure_linter
rm -rf third_party/trace-viewer/third_party/tvcm/third_party/python_gflags

# remove chrome/third_party stuff
rm -rf chrome/third_party/chromevox

# remove base/third_party stuff
rm -rf base/third_party/nspr
rm -rf base/third_party/valgrind

# remove duplicate third party stuff in the v8 tree
rm -rf v8/third_party
rm -rf v8/src/third_party

# remove ash
rm -rf chrome/browser/ui/ash
rm -rf chrome/browser/ui/views/ash

# remove empty dirs
rm -rf athena
rm -rf chromecast

# remove unused tools
find tools v8/tools -mindepth 1 -maxdepth 1 \
    ! -name generate-trig-table.py \
    ! -name protoc_wrapper \
    ! -name xdisplaycheck \
    ! -name compile_test \
    ! -name licenses.py \
    ! -name generate_* \
    ! -name idl_parser \
    ! -name imagediff \
    ! -name usb_ids \
    ! -name jsmin.py \
    ! -name js2c.py \
    ! -name clang \
    ! -name grit* \
    ! -name json* \
    ! -name gyp \
    ! -name gn \
    -execdir rm -rf {} \;

# remove documentation that isn't included in the binary packages
rm -rf chrome/common/extensions/docs

# remove unsafe symlinks
rm -f third_party/mesa/src/src/gallium/state_trackers/d3d1x/w32api

# put a reminder here
echo "This directory is needed for flot at build time." > third_party/flot/README

# remove unwanted base stuff
for dir in ash; do
    find $dir -mindepth 1 -maxdepth 1 ! -name \*.gyp\* -and ! -name chromium -execdir rm -rf {} \; 2>/dev/null;
    done

# remove unused third_party stuff
cd third_party
for dir in modp_b64 openssl harfbuzz-ng fontconfig freetype2; do
    find $dir -mindepth 1 -maxdepth 1 ! -name \*.gyp\* -and ! -name chromium -execdir rm -rf {} \; 2>/dev/null;
    done
